package entities;

import java.io.Serializable;
import javax.persistence.*;

@Embeddable
public class PendingFriendshipPK implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@ManyToOne
	@JoinColumn(name="sender", referencedColumnName="userId", nullable=false)
	private RegisteredUser sender;
	
	@ManyToOne
	@JoinColumn(name="receiver", referencedColumnName="userId", nullable=false)
	private RegisteredUser receiver;
	
	public PendingFriendshipPK() {
		// TODO Auto-generated constructor stub
	}

	public PendingFriendshipPK(RegisteredUser sender, RegisteredUser receiver) {
		super();
		this.sender = sender;
		this.receiver = receiver;
	}

	public RegisteredUser getSender() {
		return sender;
	}

	public RegisteredUser getReceiver() {
		return receiver;
	}
	
	@Override
	public boolean equals(Object o){
		try{
			if(o == null){
				return false;
			}
			PendingFriendshipPK key = (PendingFriendshipPK)o;
			if(key.receiver.equals(receiver) && key.sender.equals(sender)){
				return true;
			}
			return false;
		} catch(ClassCastException e){
			return false;
		}
	}
	
	@Override
	public int hashCode(){
		return ("" + sender.getUserId() + " " + receiver.getUserId()).hashCode();
	}

}
